home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / inline22.zip / INLINE.DOC < prev    next >
Text File  |  1988-10-05  |  21KB  |  595 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                                                      October 4, 1988
  9.  
  10.                                 INLINE ASSEMBLER
  11.                                   Version 2.20
  12.  
  13.  
  14.         OVERVIEW
  15.  
  16.         INLINE.EXE is an assembler designed to produce Inline 8086/8088 
  17.         and 8087 code for Turbo Pascal (tm) versions 3, 4 and 5 and Turbo 
  18.         C (tm) version 2.x programs.  Like other assemblers, INLINE 
  19.         accepts as input an assembly language source file and produces an 
  20.         object file.  However, in this case, the 'object' file is an 
  21.         ASCII file consisting of Inline statements which may be inserted 
  22.         into the Pascal or C program.
  23.  
  24.         Figure 1 illustrates a Pascal function with Inline code generated 
  25.         by INLINE using the source file of Figure 2.  Figures 3 and 4 
  26.         show the equivalent for a C function.
  27.  
  28.  
  29.         LOADING AND RUNNING INLINE
  30.  
  31.         First create an EXE file, INLINE.EXE, by compiling INLINE.PAS 
  32.         using version 4 or 5 of the Turbo Pascal compiler.  
  33.  
  34.         From the DOS prompt, Inline is called as:
  35.  
  36.           INLINE [/C] [Infile [Outfile]]
  37.  
  38.         The '/C' switch is used if the generated object file is to be 
  39.         formatted for C.  The two optional filenames specify the names of 
  40.         the assembly language input file and the object file to be 
  41.         generated.  If no extensions are given, .ASM and .OBJ are used by 
  42.         default.  Files with no extension may be input or created by 
  43.         using a simple '.' for the extension.  If the object filename is 
  44.         missing from the command line, an OBJ file will be created using 
  45.         the same name as the source file.  If neither filename is 
  46.         specified, then names will be requested once execution starts.
  47.  
  48.           INLINE ABC DEF
  49.  
  50.         will cause INLINE to look for a source file, ABC.ASM, and create 
  51.         an object file, DEF.OBJ.
  52.  
  53.           INLINE /C CASM
  54.  
  55.         will use the source file CASM.ASM and generate CASM.OBJ formatted 
  56.         for a C program.
  57.  
  58.         Once execution begins, INLINE will run to completion with the 
  59.         only console output being error messages.
  60.  
  61.  
  62.                                    1
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.         SYNTAX
  77.  
  78.         The appendix lists the mnemonics accepted by INLINE.  Syntax and 
  79.         mnemonics correspond to that used by most assemblers but note 
  80.         should be made of the following:
  81.  
  82.           1. Symbols may be used within instruction entries by preceding 
  83.              the symbol with a '>' (16 bit symbol) or a '<' (8 bit 
  84.              symbol).  The characters '+' and '-' are considered part of 
  85.              the symbol.  This allows computations using symbols to be 
  86.              passed on to the compiler where the computation can be made.  
  87.              For instance, in
  88.  
  89.                  MOV AX,[>Symbol+4]       ;'>Symbol+4' is passed on
  90.                  MOV AX,[BP+>Symbol+4]    ;again '>Symbol+4' is passed on
  91.                  MOV AX,>Symbol+4[BP]     ;also acceptable
  92.  
  93.              Note that
  94.  
  95.                  MOV AX,[>Symbol+4+BP]
  96.  
  97.              is not correct since the wrong instruction will be generated 
  98.              and '>Symbol+4+BP' will be passed on.
  99.  
  100.              In Turbo C, variable symbols generally require the use of 
  101.              the '&' address operator--see the discussion of the 
  102.              __emit__() function in the Turbo C manual for further 
  103.              details.  When INLINE's object code is formatted for C, the 
  104.              '<' and '>' are dropped from the output but are still 
  105.              required in the ASM source file to specify the data size.
  106.  
  107.           2. Labels (for use with jump instructions) may be defined 
  108.              simply by appending a ':' to the first item on a line.  
  109.              Avoid using CS:, DS:, ES:, and SS: as labels, as these 
  110.              specify segment overrides.
  111.  
  112.           3. Numeric entries are assumed to be decimal unless preceded by 
  113.              a '$', '0x' or '0X' which indicate a hexadecimal entry.  
  114.              Characters within single quotes may be used for numeric 
  115.              entries as:
  116.  
  117.                  CMP AL,'a'
  118.  
  119.           4. Square brackets are used to indicate 'contents of'.  If no 
  120.              square brackets are used, an immediate operand is assumed.
  121.  
  122.                  MOV AX,[>Data]  ;Load AX with the contents of Data.
  123.                  MOV AX,>Data    ;Load AX with Data.
  124.  
  125.  
  126.  
  127.  
  128.                                    2
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.           5. Instruction prefixes and segment override prefixes may 
  141.              precede the instruction on the same line or may be included 
  142.              on a previous line.  A colon is optional after the segment 
  143.              prefix.
  144.  
  145.                  ES: MOV AX,[1234]    ;ok
  146.                  REPNE MOVSB          ;ok
  147.                  MOV AX,ES:[1234]     ;incorrect syntax for INLINE
  148.  
  149.           6. Comments may be included in the source.  They are delimited 
  150.              by a ';'.
  151.  
  152.           7. Instructions which don't clearly specify the data size 
  153.              require that BYTE PTR, WORD PTR, DWORD PTR, QWORD PTR, or 
  154.              TBYTE PTR be used.  These may be abbreviated by using the 
  155.              first two letters.
  156.  
  157.                  inc byte ptr [>BData]
  158.                  DEC WO >WARRAY[DI]
  159.                  FLD QWORD [>Dbl_Real]
  160.  
  161.           8. JMP instructions may use SHORT, NEAR, or FAR (these should 
  162.              not be abbreviated).  In the absence of one of these words, 
  163.              a SHORT jump will be encoded if the label is already defined 
  164.              and is within range.  If the label is not defined, a NEAR 
  165.              JMP will be encoded unless SHORT is used.
  166.  
  167.              A FAR CALL or JMP may be made to a direct address by stating 
  168.              both the segment and offset separated by a colon.
  169.  
  170.                  CALL FAR $1234:$5678
  171.  
  172.              For Turbo Version 3 only, direct CALL's or JMP's may be made 
  173.              to other Turbo procedures and functions using symbolic 
  174.              names.  The '*' location counter reference is required (not 
  175.              available in version 4) to allow Turbo to determine the 
  176.              correct displacement, as:
  177.  
  178.                  CALL >ProcName-*-2
  179.  
  180.              Null JMP's which may be required for delay between port 
  181.              calls on the 80286, may be made as;
  182.  
  183.                  JMP >0        ;or
  184.                  JMP SHORT <0
  185.  
  186.         Normally INLINE generates only one Inline statement per source 
  187.         file.  However, the 'NEW' pseudo-instruction may be used to 
  188.         terminate one Inline statement and begin another.  Using the NEW 
  189.         instruction, it is possible to create a number of Inline 
  190.         statements with one source file.
  191.  
  192.  
  193.  
  194.                                    3
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.         FLOATING POINT INSTRUCTIONS
  208.  
  209.         An automatic WAIT (FWAIT) opcode is generated for each floating 
  210.         point instruction except for the 'no wait' instructions (those 
  211.         with 'N' for the second letter).  However, a WAIT instruction may 
  212.         be required before a floating point instruction having a segment 
  213.         override to insure the WAIT is properly positioned.
  214.  
  215.                WAIT
  216.                ES:FMUL DWORD [BX]
  217.  
  218.  
  219.         CAVEATS
  220.  
  221.         INLINE has no way of knowing the value of any symbols used so the 
  222.         user should be especially careful when using the '<' byte size 
  223.         specifier.  A case in point is when referring to stack variables.
  224.         In Turbo Pascal, consider the following:
  225.  
  226.              MOV AX,<ABC[bp]    vs
  227.              MOV AX,>ABC[bp]
  228.  
  229.         The use of '<' here will result in saving one byte but will only 
  230.         work correctly if ABC is in the range -128 to 127.  Stack offsets 
  231.         often exceed this in Turbo 4, so it is much safer to use  '>'.
  232.  
  233.         When accessing auto variables in Turbo C, it is essential to be 
  234.         certain if the stack displacement is within the range of one byte 
  235.         or requires two bytes.  This is because the __emit__() function
  236.         of Turbo C apparently does not provide a way to extend a byte 
  237.         displacement to two bytes when the '&' operator is used.  Thus
  238.  
  239.              mov ax,>&abc[bp]
  240.  
  241.         will cause INLINE to generate an instruction requiring a two 
  242.         byte displacement but the Turbo C compiler will only generate
  243.         one byte if &abc is in the range of -128 to 127.  Functions which
  244.         have only a few simple auto variables will meet the -128 to 127
  245.         requirement and it's safe in those cases to use the '<' operator.
  246.         For functions which have many variables or arrays, structures,
  247.         strings defined locally, it's probably best to avoid referring to
  248.         the auto variables from the Inline code.  This one byte, two byte
  249.         problem only applies to local variables.  Global variables
  250.         always have a two byte displacement and an override is available
  251.         for defined constants.
  252.  
  253.         Note that just because a constant is byte size does not make it 
  254.         safe to use '<'.  If ABC were defined as =255, then CMP BX,<ABC 
  255.         would not assemble correctly as a constant in the range -128 to 
  256.         127 would be expected.  Here again, it's safer to use '>'.
  257.  
  258.  
  259.  
  260.                                    4
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.         When using register variables in C, it's very important to save 
  273.         and restore the SI and DI registers if these registers are used 
  274.         by the Inline code.  (See figure 4.)  Also, any variables referred 
  275.         to within the __emit__() function will not be assigned to 
  276.         registers.
  277.  
  278.         Many instructions may be correctly assembled in more than one 
  279.         way.  This has caused some confusion in the past when INLINE 
  280.         produced a byte sequence different from that expected.  When in
  281.         doubt, check the byte sequence using DEBUG or run it through
  282.         UNINLINE for verification.
  283.  
  284.  
  285.         RESTRICTIONS
  286.  
  287.         The object file is limited to 32k.  This includes comments and
  288.         spaces.
  289.  
  290.         Symbols (including any addons from + and -) are limited to 32
  291.         characters.
  292.  
  293.         Labels may be used in jump statements only and not as data 
  294.         references.  While there is a DB pseudo-opcode, it is not very 
  295.         useful with this restriction.
  296.  
  297.         The number of statement labels that may be defined is limited 
  298.         only by the heap space available.
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.                                    5
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.         VERSIONS
  339.  
  340.         2.00 Added 8087 instructions.
  341.         2.01 Fixed bug which wiped out INT $A vector.
  342.         2.02 Fixed bug which prevented labels from starting with BY, WO, 
  343.              DW, QW, and TB.
  344.         2.1  Add NEW pseudo-instruction.  Fixed bug which occurred with 
  345.              filenames having no extension.  Other bugs fixed, notably 
  346.              those effecting IN and OUT.
  347.         2.11 Calculate restricted range for short jumps correctly.
  348.              Fix bug so CALL/JMP <register> may be used.
  349.         2.12 Allow CALL and JMP direct instructions.
  350.         2.13 Allow JMP >0 and JMP SHORT <0 for null JMP's.
  351.         2.14 Change output format to better sync with TMAP's line 
  352.              numbers.
  353.         2.15 Fix 'shl cl,1' which assembled as shl cl,cl
  354.         2.16 Change byte size check in MemReg so the likes of
  355.                      MOV [DI+$FE],AX will assemble right.
  356.              Allow ',' in DB pseudo op instruction.
  357.         2.17 Convert source to Turbo 4.
  358.         2.18 Implement the sign extension bit for some instructions
  359.         2.19 Fix problem in 2.18 with sign extension bit on AX,AL 
  360.              instructions.
  361.         2.20 Add C output format.  Fix bug in cmp bx,>abc which assembled
  362.              for a byte size constant.
  363.  
  364.  
  365.         (C) Copyright 1985,86,87,88 by L. David Baldwin.
  366.  
  367.         INLINE may be copied and distributed freely providing that no fee 
  368.         is charged and it is not part of a package for which a charge is 
  369.         made.
  370.  
  371.         Please report all bugs, suggestions, and problems to Dave 
  372.         Baldwin, CompuServe ID #76327,53.
  373.  
  374.              22 Fox Den Rd., (Summer)     144 13th St. East,  (Winter)
  375.              Hollis, NH 03049             Tierra Verde, FL 33715
  376.              (603) 465-7857               (813) 867-3030
  377.  
  378.  
  379.              Turbo Pascal and Turbo C are trademarks of Borland 
  380.              International Inc.
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.                                    6
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.         FUNCTION Scan(Limit :Integer; Ch :Char; Var T ): Integer;
  405.          {Scan Limit characters for Ch. Return the number of characters
  406.           skipped to find a match.  If not found, return result=Limit.
  407.           Limit may be negative for a backwards scan.}
  408.         Var
  409.           Rslt : Integer;
  410.         begin
  411.         Inline(
  412.           $FC/              {    cld              ;assume forward}
  413.           $8A/$86/>Ch/      {    mov al,>Ch[bp]   ;char to search for}
  414.           $8B/$8E/>Limit/   {    mov cx,>Limit[bp];bytes to search}
  415.           $09/$C9/          {    or cx,cx         ;check sign}
  416.           $9C/              {    pushf            ;save flags}
  417.           $79/$03/          {      jns x1}
  418.           $F7/$D9/          {    neg cx           ;make positive}
  419.           $FD/              {    std              ;but search in reverse}
  420.           $89/$CA/          {x1: mov dx,cx        ;save full count}
  421.           $C4/$BE/>T/       {    les di,>T[bp]    ;ptr to start}
  422.           $F2/$AE/          {    repne scasb      ;search}
  423.           $75/$01/          {      jne x2}
  424.           $41/              {    inc cx           ;found a match}
  425.           $29/$CA/          {x2: sub dx,cx        ;find count to match}
  426.           $9D/              {    popf}
  427.           $79/$02/          {      jns x3}
  428.           $F7/$DA/          {    neg dx           ;make negative if reverse}
  429.           $89/$96/>Rslt);   {x3: mov >Rslt[bp],dx ;put in function result}
  430.         Scan := Rslt;
  431.         end;
  432.  
  433.                        Figure 1: Pascal Function using Inline Code
  434.  
  435.             cld              ;assume forward
  436.             mov al,>Ch[bp]   ;char to search for
  437.             mov cx,>Limit[bp];bytes to search
  438.             or cx,cx         ;check sign
  439.             pushf            ;save flags
  440.               jns x1
  441.             neg cx           ;make positive
  442.             std              ;but search in reverse
  443.         x1: mov dx,cx        ;save full count
  444.             les di,>T[bp]    ;ptr to start
  445.             repne scasb      ;search
  446.               jne x2
  447.             inc cx           ;found a match
  448.         x2: sub dx,cx        ;find count to match
  449.             popf
  450.               jns x3
  451.             neg dx           ;make negative if reverse
  452.         x3: mov >Rslt[bp],dx ;put in function result
  453.  
  454.                       Figure 2:  INLINE Input File for Pascal
  455.  
  456.  
  457.  
  458.                                    7
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.         int scan(int limit, char ch, void far *t)
  471.         /* Scan Limit characters for ch. Return the number of characters
  472.            skipped to find a match.  If not found, return result=limit.
  473.            limit may be negative for a backwards scan. */
  474.         {int rslt;
  475.         __emit__(
  476.           0x57,            /*    push di           ;Important if reg vars used*/
  477.           0xFC,            /*    cld               ;assume forward*/
  478.           0x8A,0x46,&ch,   /*    mov al,<&ch[bp]   ;char to search for*/
  479.           0x8B,0x4E,&limit,/*    mov cx,<&limit[bp];bytes to search*/
  480.           0x09,0xC9,       /*    or cx,cx          ;check sign*/
  481.           0x9C,            /*    pushf             ;save flags*/
  482.           0x79,0x03,       /*      jns x1*/
  483.           0xF7,0xD9,       /*    neg cx            ;make positive*/
  484.           0xFD,            /*    std               ;but search in reverse*/
  485.           0x89,0xCA,       /*x1: mov dx,cx         ;save full count*/
  486.           0xC4,0x7E,&t,    /*    les di,<&t[bp]    ;ptr to start*/
  487.           0xF2,0xAE,       /*    repne scasb       ;search*/
  488.           0x75,0x01,       /*      jne x2*/
  489.           0x41,            /*    inc cx            ;found a match*/
  490.           0x29,0xCA,       /*x2: sub dx,cx         ;find count to match*/
  491.           0x9D,            /*    popf*/
  492.           0x79,0x02,       /*      jns x3*/
  493.           0xF7,0xDA,       /*    neg dx            ;make negative if reverse*/
  494.           0x89,0x56,&rslt, /*x3: mov <&rslt[bp],dx ;put in function result*/
  495.           0x5F);           /*    pop di            ;restore saved di*/
  496.          return rslt;
  497.         }
  498.                        Figure 3: C Function using Inline Code
  499.  
  500.             push di           ;Important if reg vars used
  501.             cld               ;assume forward
  502.             mov al,<&ch[bp]   ;char to search for
  503.             mov cx,<&limit[bp];bytes to search
  504.             or cx,cx          ;check sign
  505.             pushf             ;save flags
  506.               jns x1
  507.             neg cx            ;make positive
  508.             std               ;but search in reverse
  509.         x1: mov dx,cx         ;save full count
  510.             les di,<&t[bp]    ;ptr to start
  511.             repne scasb       ;search
  512.               jne x2
  513.             inc cx            ;found a match
  514.         x2: sub dx,cx         ;find count to match
  515.             popf
  516.               jns x3
  517.             neg dx            ;make negative if reverse
  518.         x3: mov <&rslt[bp],dx ;put in function result
  519.             pop di            ;restore saved di
  520.                       Figure 4:  INLINE Input File for C
  521.  
  522.  
  523.  
  524.                                    8
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.         APPENDIX
  537.  
  538.           8086/8088 Opcode Mnemonics Recognized by INLINE
  539.  
  540.                 AAA       HLT       JNE       LOOPNZ    ROR    
  541.                 AAD       IDIV      JNG       LOOPZ     SAHF   
  542.                 AAM       IMUL      JNGE      MOV       SAL    
  543.                 AAS       IN        JNL       MOVSB     SAR    
  544.                 ADC       INC       JNLE      MOVSW     SBB    
  545.                 ADD       INT       JNO       MUL       SCASB  
  546.                 AND       INTO      JNP       NEG       SCASW  
  547.                 CALL      IRET      JNS       NOP       SHL    
  548.                 CBW       JA        JNZ       NOT       SHR    
  549.                 CLC       JAE       JO        OR        SS     
  550.                 CLD       JB        JP        OUT       STC    
  551.                 CLI       JBE       JPE       POP       STD    
  552.                 CMC       JC        JPO       POPF      STI    
  553.                 CMP       JCXZ      JS        PUSH      STOSB  
  554.                 CMPSB     JE        JZ        PUSHF     STOSW  
  555.                 CMPSW     JG        LAHF      RCL       SUB    
  556.                 CS        JGE       LDS       RCR       TEST   
  557.                 CWD       JL        LEA       REP       WAIT   
  558.                 DAA       JLE       LES       REPE      XCHG   
  559.                 DAS       JMP       LOCK      REPNE     XLAT   
  560.                 DB        JNA       LODSB     REPNZ     XOR    
  561.                 DEC       JNAE      LODSW     REPZ   
  562.                 DIV       JNB       LOOP      RET    
  563.                 DS        JNBE      LOOPE     RETF   
  564.                 ES        JNC       LOOPNE    ROL    
  565.  
  566.  
  567.           8087 Opcode Mnemonics Recognized by INLINE
  568.  
  569.                 F2XM1     FDIVRP    FLD       FNOP      FSTP   
  570.                 FABS      FENI      FLD1      FNSAVE    FSTSW  
  571.                 FADD      FFREE     FLDCW     FNSTCW    FSUB   
  572.                 FADDP     FIADD     FLDENV    FNSTENV   FSUBP  
  573.                 FBLD      FICOM     FLDL2E    FNSTSW    FSUBR  
  574.                 FBSTP     FICOMP    FLDL2T    FPATAN    FSUBRP 
  575.                 FCHS      FIDIV     FLDLG2    FPREM     FTST   
  576.                 FCLEX     FIDIVR    FLDLN2    FPTAN     FXAM   
  577.                 FCOM      FILD      FLDPI     FRNDINT   FXCH   
  578.                 FCOMP     FIMUL     FLDZ      FRSTOR    FXTRACT
  579.                 FCOMPP    FINCSTP   FMUL      FSAVE     FYL2X  
  580.                 FDECSTP   FINIT     FMULP     FSCALE    FYL2XP1
  581.                 FDISI     FIST      FNCLEX    FSQRT     FWAIT  
  582.                 FDIV      FISTP     FNDISI    FST    
  583.                 FDIVP     FISUB     FNENI     FSTCW  
  584.                 FDIVR     FISUBR    FNINIT    FSTENV 
  585.  
  586.  
  587.  
  588.  
  589.  
  590.                                    9
  591.  
  592.  
  593.  
  594.  
  595.